package self;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Score {
    public static void main(String[] args) throws Exception {
        func();
    }

    private static void func() throws Exception{
        System.out.print("请输入分数:");
        try {
            double score = new Scanner(System.in).nextDouble();
            System.out.println(score+"分的成绩等级为:"+level(score));
        } catch (IllegalScoreException e) {
            System.out.println("*****成绩录入错误,请检查录入");
            func();
        } catch (InputMismatchException e){
            System.out.println("*****请输入阿拉伯数字");
            func();
        }
    }

    private static String level(double score) throws IllegalScoreException {
        if (score>=100){
            throw new IllegalScoreException();
        }else if (score>=90){
            return "A";
        }else if (score>=80){
            return "B";
        }else if (score>=70){
            return "C";
        }else if (score>=60){
            return "D";
        }else if (score>=0){
            return "不及格";
        }else {
            throw new IllegalScoreException();
        }
    }


}
// 自定义非法分数异常类
class IllegalScoreException extends Exception{
    public IllegalScoreException(){
        super();
    }
    public IllegalScoreException(String massage){
        super(massage);
    }
}
